<?php

/**
 * @author ict.sonla.gov.vn
 * @copyright 2012
 */
 
defined('DSVH') or die('Restricted access');
//G?i t?p tin giao di?n trong thu m?c view/theme/template tuong ?ng
 if(!$_SESSION['loged']){
         header('LOCATION: index.php?module=canbo&act=login');  
         exit();
     }
include('controller/c_thongke.php');     
include ('model/m_huongdan.php');
$page = $_GET['act'];
 switch($page){
    case 'list':
    //Get language
    require('language/huongdan/list.php');
    $heading_title = heading_title;
    $title = heading_title;
    $button_add = button_add;
    $button_edit = button_edit;
    $button_delete = button_delete;
    
    $ma_dan_toc = ma_dan_toc;
	$ten_huong_dan = ten_dan_toc;
    $thao_tac = thao_tac;
    $link_add ='index.php?module=huongdan&act=add';
    $link_list ='index.php?module=huongdan&act=list';
    
      if($_POST['selected']==""){
        $err['exist'] = chua_chon;
        $error_name = $err['exist'];
        }
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    //kiem tra du lieu cua from
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid){
      foreach($_POST['selected'] as $id){
        
        delhuongdan($id);
         
        $_SESSION['success'] = del_success;
         
      }  
   
    //chuyen huong ve list
    header('LOCATION: '.$link_list);
    }
     
    if($_REQUEST['page']==""){
       $page = 1;
    }
    else{
        
       $page = $_REQUEST['page'];
     
    }
    //get input for class page
    $limit = 10;
    $start = ($page - 1) * $limit;
    $list_huongdan = getlisthuongdan($start,$limit);
    $total = totalhuongdan();
    // paging
    $paging = new Pagination();
    $paging->total = $total;
    $paging->limit = $limit;
    $paging->url = "index.php?module=huongdan&act=list&page={page}";
    $paging->page = $page;
    $pagination = $paging->render();
 
    require('view/template/huongdan/list_huongdan.tpl');
    break;
	
	//case them chuc danh
	case 'add':
	require('language/huongdan/add.php');
	$heading_title = heading_title;
    $ma_dan_toc = ma_dan_toc;
	$ten_dan_toc = ten_dan_toc;
    $motachitiet = mo_ta_chi_tiet;
    $motachung = mo_ta_chung;
    $hinhdaidien = hinh_dai_dien;
    
    $link_list = 'index.php?module=huongdan&act=list';
    $loaihuongdan_list = getlistloaihuongdan();
    
    if($_POST['ten_huong_dan']==""){
        $err['exist'] = chua_nhap_ten;
        $error_name = $err['exist'];
             }
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid)
    {
    insertHuongDan($_POST);
    $_SESSION['success'] = add_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);  
    exit();  
    }
    require('view/template/huongdan/add_huongdan.tpl');
    break;
    
    //case sua dan toc
    case 'edit':
    require('language/huongdan/edit.php');
    $heading_title = heading_title;
    $ma_dan_toc = ma_dan_toc;
    $ten_huong_dan = ten_dan_toc;
    $motachitiet = mo_ta_chi_tiet;
    $motachung = mo_ta_chung;
    $hinhdaidien = hinh_dai_dien;
    $link_list = 'index.php?module=huongdan&act=list';
    $id = $_REQUEST['id'];
    $loaihuongdan_list = getlistloaihuongdan();
    $huongdan = gethuongdan($id);
    
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
    edithuongdan($id, $_POST);
    $_SESSION['success'] = edit_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);    
    exit();
    
    }
     
    require('view/template/huongdan/edit_huongdan.tpl');
    break; 
    
    case 'del':
    get_file('language/huongdan/delphp');
    $link_list = 'index?module=huongdan&act=list';
    $id = $_REQUEST['id'];
    $huongdan = gethuongdan($id);
    if($huongdan['avatar']){
           unlink('./data/image/huongdan/'.$huongdan['avatar']);
         }
    delhuongdan($id);
     $_SESSION['success'] = del_success;
    //chuyen huong ve list
     header('LOCATION: '.$link_list);  
     exit();
         
    
    break;  
    
    
    case 'view_hv':
    require('language/huongdan/view_hv.php');
    $heading_title = heading_title;
    $title =title;
    $ma_dan_toc = ma_dan_toc;
    $ten_huong_dan = ten_dan_toc;
    $motachitiet = mo_ta_chi_tiet;
    $motachung = mo_ta_chung;
    $hinhdaidien = hinh_dai_dien;
    $link_list = 'index.php?module=huongdan&act=list';
    $id = $_REQUEST['id'];
    $loaihuongdan_list = getlistloaihuongdan();
    
    $huongdan = gethuongdan(29);
   
    require('view/template/huongdan/view_huongdan_hv.tpl');
    break; 
    
    case 'view_pvt':
    require('language/huongdan/view_pvt.php');
    $heading_title = heading_title;
      $title =title;
    $ma_dan_toc = ma_dan_toc;
    $ten_huong_dan = ten_dan_toc;
    $motachitiet = mo_ta_chi_tiet;
    $motachung = mo_ta_chung;
    $hinhdaidien = hinh_dai_dien;
    $link_list = 'index.php?module=huongdan&act=list';
    $id = $_REQUEST['id'];
    $loaihuongdan_list = getlistloaihuongdan();
    
    $huongdan = gethuongdan($id);
   
    require('view/template/huongdan/view_huongdan_pvt.tpl');
    break; 
    
    case 'view_dacsac':
    require('language/huongdan/view_dacsac.php');
    $heading_title = heading_title;
      $title =title;
    $ma_dan_toc = ma_dan_toc;
    $ten_huong_dan = ten_dan_toc;
    $motachitiet = mo_ta_chi_tiet;
    $motachung = mo_ta_chung;
    $hinhdaidien = hinh_dai_dien;
    $link_list = 'index.php?module=huongdan&act=list';
    $id = $_REQUEST['id'];
    $loaihuongdan_list = getlistloaihuongdan();
    
    $huongdan = gethuongdan($id);
   
    require('view/template/huongdan/view_huongdan_dacsac.tpl');
    break; 
}
?>